/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package YottaTron.Sprites;

import YottaTron.*;
import YottaTron.Actions.Action;
import YottaTron.Actions.MovementVector;
import YottaTron.Behaviors.Behavior;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.LinkedList;

/**
 *
 * @author Cenda
 */
public abstract class Sprite {

    public static final byte SPEED_CHANGED = 0;
    public static final byte DIRECTION_CHANGED = 1;
    

    public int ID,  width,  height; // hracum bude pridelovat id server
    public double x,  y;
    private double dx,  dy;
    public double direction,  speed;
    private ArrayList<Action> paralelActions;
    private LinkedList<Action> actions;
    public LinkedList<MovementVector> movementHistory;
   
    public boolean active;
    public boolean variableChanged;
    public double collisionDamage;
    public Behavior behavior;
    
    //oznacuje kdo zpusobuje poskozeni vyvolane timto spritem, treba u strely to bude shooterID, u prekazky to bude stejne jako jeji ID
    

    public Sprite(double x, double y, int width, int height, int ID) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.ID = ID;
        active = true;
        paralelActions = new ArrayList<Action>();
        actions = new LinkedList<Action>();
        movementHistory = new LinkedList<MovementVector>();
        variableChanged = false;
       
    }

    public double getDirection() {
        return direction;
    }

    public double getDx() {
        return dx;
    }

    public double getDy() {
        return dy;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public double getCenterY() {

        return y + height / 2;
    }

    public double getCenterX() {
        return x + width / 2;
    }

    public void setX(double x) {
        this.x = x;
    }

    public void setY(double y) {
        this.y = y;
    }

    public void setDx(double dx) {
        this.dx = dx;
    }

    public void setDy(double dy) {
        this.dy = dy;
    }

    public void setDirection(double Direction) {
        this.direction = Direction;
    }

    public void handleCollision(Sprite target) {
    }

    public void changeDirection(double angle) {
        while (angle <= 0) {
            angle = angle + Math.PI * 2;
        }
        while (angle >= Math.PI * 2) {
            angle = angle - Math.PI * 2;
        }
        setDirection(angle);

        dx = Math.sin(direction) * speed;
        dy = -Math.cos(direction) * speed;
    }

    public Action getAction() {
        if (actions.isEmpty()) {
            return null;
        } else {
            return actions.get(0);
        }
    }

    public ArrayList<Action> getParalelActions() {
        return paralelActions;
    }

    public void removeAction() {
        actions.remove(0);
    }

    public void removeParalelAction(Action act) {
        paralelActions.remove(act);
        //System.out.println("action " + act.toString() + " removed");
        }

    public void removeParalelAction(int type, float finishTime) {
        for(int i = 0; i <paralelActions.size(); i++){
            Action action = paralelActions.get(i);
        if(action.type==type){
            
            action.finishTime = finishTime;
            action.finished = true;
           
            //System.out.println("removing paralel action " + action.toString());
        }
        }
    }

    

    public void removeAllActions() {
        actions.clear();
    }

    public void setAction(Action action) {
        this.actions.add(action);
    }

    public void setParalelAction(Action action) {
        this.paralelActions.add(action);
        
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
        dx = Math.sin(direction) * speed;
        dy = -Math.cos(direction) * speed;
    }

    public void stop() {
        setSpeed(0);
    }

    public void destroySprite(Runner runner) {
    }

    public int getID() {
        return ID;
    }

    public boolean isActive() {
        return active;
    }

    public void damage(int damage) {
    }

    public ArrayList<Point2D> getShape() {
        return null;
    }
    //zjisti na kterych polickach herniPole se sprite nachazi

    public ArrayList<Point2D> getOccupiedCells() {
        return null;
    }

    public double getAcceleration(){
    return 0;
    }

    public double getBrakePower(){
    return 0;
    }

    public double getTurnSpeed(){
    return 0;
    }

    public double getMaxSpeed(){
    return 0;
    }



}
